package com.langfeiyes.pattern.flyweight.v2;



import com.langfeiyes.pattern.flyweight.ConcreteFlyWeight;
import com.langfeiyes.pattern.flyweight.IFlyWeight;

import java.util.*;

/**
 * 卡片管理工厂
 */
public class CardFactory {
    //卡牌所有花色
    public static final String[] colours = new String[]{"红桃","黑桃","方块","梅花"};

    //卡牌池：享元池
    private Map<String, ICard> map = new HashMap<>();
    //抽牌
    public ICard takeout(){
        //随机抽取花色
        int i = new Random().nextInt(colours.length);
        String color = colours[i];
        //随机抽取点数
        int num = new Random().nextInt(13) + 1;
        if(!map.containsKey(color)){
            map.put(color, new PlayCard(color));
        }
        ICard iCard = map.get(color);
        iCard.setNum(num);
        return iCard;
    }
}
